<?php
class CMRPageShowOldCategory extends CMRPage
{
	private $section;
	private $category;
	private $categoryName;
	
	private $displayLimit = 20;
	private $displayStart = 0;
	private $displayLetter;
	
	public function __construct($database, $section, $category)
	{
		parent::__construct($database);
		$this->section = $section;
		$this->category = $category;
		
		if(isset($_POST['CategorySearchLetterLetter']))
			$this->displayLetter=$_POST['CategorySearchLetterLetter'];
		
		if(isset($_POST['CategorySearchLimitNumber']))
			$this->displayLimit=$_POST['CategorySearchLimitNumber'];
			
		if(isset($_POST['CategorySearchLimitStart']))
			$this->displayStart=$_POST['CategorySearchLimitStart'];
			
			
		$enumCategories = new Enumeration($this->Database,$this->section."CategoryNames");
		$categories = $enumCategories->getArray();
		
		$this->categoryName=$categories[$this->category];
	
	}
	
	protected function getResources()
	{
		$resources = array();
		
		// if no alphabet letter or display limit specified, default is All letters, and 20 items
		
//		if(isset)
		
		$sql =  "SELECT res.*,cat.* FROM Resources as res ";
		$sql .= "INNER JOIN ".$this->section."Categorys AS cat ON res.ResourceID=cat.ResourceID ";
		$sql .= "WHERE DeletedBy = '0' AND StatusTypeID = '3' AND cat.".$this->section."CategoryNameID=".$this->category." ";
		if($this->displayLetter<>'')
			$sql .= "AND ResourceTitle LIKE '".$this->displayLetter."%' ";
		$sql .= "ORDER BY ResourceTitle ";
		$sql .= "LIMIT ".$this->displayStart.",".$this->displayLimit;
//		echo $sql."<br>\n";
		$this->Database->ExecuteSQL($sql);
		while($row = $this->Database->getRow())
		{
			$resource = new Resource($this->Database->Recopy(),$row['ResourceID']);
			$resource->setCurrentUserGroup($this->userGroup);
			//			$resource->loadData($row['ResourceID'],$row['ResourceTitle'],$row['ResourceDescription'],$row['ResourceTypeID'],"","",,,,);
			array_push($resources,$resource);
		}
				
		return $resources;
	}
	
	protected function getContentsDiv()
	{
		$resourceID = new Hidden();
		$resourceID->setName("ResourceID");
		$html = $resourceID->getHTML();
	
		$category = new Hidden();
		$category->setName("Category");
		$category->setValue($_POST['Category']);
		$html .= $category->getHTML();
	
		$html .= "<div id=\"content\">\n";
		$html .= "<h1>".$this->categoryName."</h1>\n";
		
		$html .= "<p style=\"text-align: center;\">\n";
		
		$html .= "<img id=\"ImgChoral\" width=\"130\" height=\"80\" ";
		if($this->section!='Choral')
		{
			$html .= "onMouseOver=\"OnMouseOverChoral();\" ";
			$html .= "onMouseOut=\"OnMouseOutChoral();\" ";
		}
		$html .= "onclick=\"OnClickChoral();\" ";
		$html .= "src=\"../Images/Choral";
		if($this->section!='Choral')$html .= 'A';
		$html .= ".png\" />&nbsp;&nbsp;&nbsp;\n";
		
		$html .= "<img id=\"ImgOrgan\" width=\"130\" height=\"80\" ";
		if($this->section!='Organ')
		{
			$html .= "onMouseOver=\"OnMouseOverOrgan();\" ";
			$html .= "onMouseOut=\"OnMouseOutOrgan();\" ";
		}
		$html .= "onclick=\"OnClickOrgan();\" ";
		$html .= "src=\"../Images/Organ";
		if($this->section!='Organ')$html .= 'A';
		$html .= ".png\" />&nbsp;&nbsp;&nbsp;\n";
		
		$html .= "<img id=\"ImgLiturgy\" width=\"130\" height=\"80\" ";
		if($this->section!='Liturgy')
		{
			$html .= "onMouseOver=\"OnMouseOverLiturgy();\" ";
			$html .= "onMouseOut=\"OnMouseOutLiturgy();\" ";
		}
		$html .= "onclick=\"OnClickLiturgy();\" ";
		$html .= "src=\"../Images/Liturgy";
		if($this->section!='Liturgy')$html .= 'A';
		$html .= ".png\" />&nbsp;&nbsp;&nbsp;\n";
		
		$html .= "<img id=\"ImgProfessional\" width=\"130\" height=\"80\" ";
		if($this->section!='Professional')
		{
			$html .= "onMouseOver=\"OnMouseOverProfessional();\" ";
			$html .= "onMouseOut=\"OnMouseOutProfessional();\" ";
		}
		$html .= "onclick=\"OnClickProfessional();\" ";
		$html .= "src=\"../Images/Professional";
		if($this->section!='Professional')$html .= 'A';
		$html .= ".png\" />&nbsp;&nbsp;&nbsp;\n";
		
		$html .= "</p>\n";
		$html .= "<p> This section contains the resources contained in the ".$this->categoryName." category of the ".$this->section." section. Choose a resource from the list below.</p>\n";

		if(($this->userGroup=="Editors")||($this->userGroup=="Supervisors"))
		{
			$hidden = new Hidden();
			$hidden->setName("SubAction");
			$html .= $hidden->getHTML();

/*			$hidden = new Hidden();
			$hidden->setName("ResourceID");
			$html .= $hidden->getHTML();
*/		

		}
		
		$panel = new AlphabetSelectPanel();
		$panel->setName("CategorySearchLetter");
		$panel->setDisplayLetter($this->displayLetter);
		$html .= $panel->getHTML();
		
		$panel = new DisplayLimitPanel();
		$panel->setName("CategorySearchLimit");
		$panel->setLimit($this->displayLimit);
		$panel->setStart($this->displayStart);
		//		echo "Display limit = ".$this->displayLimit."<br>\n";
		$html .= $panel->getHTML();
		
		$resources = $this->getResources();
		if(count($resources)==0)$html .= "<p>There are currently no resources in this section</p>\n";
		foreach ($resources as $resource)
		{
			$html .= $resource->getSummaryHTML();
		}
				
		$html .= "</div>\n";
		return $html;
	}
	
}